﻿using Bids.Core.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using Telerik.OpenAccess.Metadata;
using Telerik.OpenAccess.Metadata.Fluent;
namespace Bids.Core.DomainObjects
{
	/// <summary>
	/// 行业
	/// </summary>
	[Serializable]
    public class Trade : IEntity
	{
        public Trade()
        {
            this.Tasks = new List<Task>();
        }
		/// <summary>
		/// 
		/// </summary>
        public virtual int ID { set; get; }
		/// <summary>
		/// 名称
		/// </summary>
        public virtual string Name { set; get; }

        public virtual IList<Task> Tasks { get; set; }

        public static MappingConfiguration<Trade> CreateConfiguration()
        {
            var threadMapping = new MappingConfiguration<Trade>();
            threadMapping.MapType(t => new
            {
                t.ID,
                t.Name
            }).ToTable("Trades");
            threadMapping.HasProperty(t => t.ID).IsIdentity(KeyGenerator.Autoinc);
            threadMapping.HasAssociation(t => t.Tasks).WithOpposite(d => d.Trade).HasConstraint((t, d) => t.ID == d.TradeId);

            return threadMapping;
        }

	}
}

